<?php
// -----------------------------------------------------------------------------

include "global/functions.php";
include "config/config.php";
include "DBManager.php";
include "createDBIfNotExists.php";

// 取消超时
set_time_limit(0);

$db = new DBManager($dbPath);

// -----------------------------------------------------------------------------

if (empty($_POST['startDate']) || empty($_POST['separator']) || empty($_POST['contents'])) {
    exit("需要传入有效的参数。");
}

$startDate = $_POST['startDate'];
$separator = $_POST['separator'];
$contents = $_POST['contents'];

// -----------------------------------------------------------------------------
?>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>批量制定复习计划</title>
    <link rel="stylesheet" href="resources/bootstrap-4.3.1-dist/css/bootstrap.min.css">
</head>
<body>

<!-- ----------------------------------------------------------------------- -->
<?php include 'global/globalNavBar.php'; ?>
<!-- ----------------------------------------------------------------------- -->

<div class="container mt-2">

    <?php

    try {

        $contentArray = explode($separator, $contents);
        $dateToInsnert = $startDate;

        foreach ($contentArray as $contentToInsert) {
            $db->appendContent($dateToInsnert, $contentToInsert);
            $dateToInsnert = getTheDate($dateToInsnert, "+", 1);
        }

        echo "数据插入成功。";

    } catch (Exception $e) {
        echo $e->getMessage();
    }

    ?>

</div>

<!-- ----------------------------------------------------------------------- -->
<script src="resources/jquery/jquery-3.4.0.min.js"></script>
<script src="resources/bootstrap-4.3.1-dist/js/bootstrap.min.js"></script>
<!-- ----------------------------------------------------------------------- -->

</body>
</html>